package Utils;

import javax.mail.*;
import javax.mail.internet.*;

import Entity.E_Mail;
import Entity.WorkerEmails;

import java.util.*;

public class MailHandler {
	
	final public static String SUBJECT_MEETING_CREATED = "Meeting created";

	final private static String senderEmailID = "nirporat@gmail.com";
	final private static String senderPassword = "nir7424394";
	final private static String emailSMTPserver = "smtp.gmail.com";
	final private static String emailServerPort = "465";
//	private static String meetingDate;

	public static void SendMail(String receiverEmailID, String emailSubject, String emailBody)
	{
		Properties props = new Properties();
		props.put("mail.smtp.user",senderEmailID);
		props.put("mail.smtp.host", emailSMTPserver);
		props.put("mail.smtp.port", emailServerPort);
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.auth", "true");
		// props.put("mail.smtp.debug", "true");
		props.put("mail.smtp.socketFactory.port", emailServerPort);
		props.put("mail.smtp.socketFactory.class",
		"javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.socketFactory.fallback", "false");

		SecurityManager security = System.getSecurityManager();

		try
		{
			Authenticator auth = new SMTPAuthenticator();
			Session session = Session.getInstance(props, auth);
			// session.setDebug(true);
	
			MimeMessage msg = new MimeMessage(session);
			msg.setText(emailBody);
			msg.setSubject(emailSubject);
			msg.setFrom(new InternetAddress(senderEmailID));
			msg.addRecipient(Message.RecipientType.TO , new InternetAddress(receiverEmailID));
			Transport.send(msg);
		}
		catch (Exception mex)
		{
			mex.printStackTrace();
		}
	}
	
	public static void Send_Customer_Manager_Mail(String target, String emailSubject, String emailBody)
	{
		
		SendMail(target, emailSubject, emailBody);
		
	}
	
	public static void generateMeetingMailBody(E_Mail mail)
	{
		String sBody = "Hello "+mail.getgName()+" & "+mail.getbName()+",\n";
		
		sBody += " A meeting was created with you on: " + mail.getmDate() + " at: " + mail.getmTime() + " O'Clock";
		sBody += "\nThank You!";
		sBody += "\nBest Regards Katom Photography";
		Send_Customer_Manager_Mail(mail.getC_mail(),"A New Meeting With KATOM Photography ", sBody);
		
	}
	
	public static void generateMeetingMailForManager(E_Mail mail)
	{
		String sBody = "A new meeting has been set for " + mail.getmDate() + " ";
		
		sBody += "at " +mail.getmTime() + " O'Clock with the couple" + mail.getgName() + " " + mail.getbName() + ".";
		sBody +="\nBest Regards Katom Photography";
		
		Send_Customer_Manager_Mail(mail.getM_mail(),"A New Meeting With " +mail.getgName()+ " & " +mail.getbName()+ ".", sBody);
	}
	
	public static void generateReadyMailForCustomer(E_Mail mail){
		String sBody = "Hello "+mail.getgName()+" & "+mail.getbName()+".";
		
		sBody +="The work on your photos and videos has done,\nYou are welcome to arrive and pick them up\n";
		sBody +="\nBest Regards Katom Photography";
		
		Send_Customer_Manager_Mail(mail.getC_mail(), "Katom invite you to pick up your photoes and videos", sBody);
	}
	
	public static void generateShiftMailForWorker(String  email){
		
		String sBody = "Hello , A new Event has been created and you are a part of the crew.";
		
		sBody += "\n For further details please view shit schedule in the system";
		sBody +="\nBest Regards Katom Photography";
		Send_Customer_Manager_Mail(email, "You where schedule to event ", sBody);
	}

	public static void newPasswordSentEnail(String  email,String pass){
		
		String sBody = "Hello , You have been added to Katom photography company.";
		
		sBody += "\n This is your password to first entry to the system: "+pass+"";
		sBody +="\nBest Regards Katom Photography";
		Send_Customer_Manager_Mail(email, "congratulation, you are new worker in Katom photography  ", sBody);
	}
	
public static void readyPhotosMail(String  email){
		
		String sBody = "Hello , Your phtos are ready :) ";
		
		sBody += "\n You can come to Katom photography company to colect them.";
		sBody += "\n Please call our office before coming.";
		sBody +="\nBest Regards Katom Photography";
		Send_Customer_Manager_Mail(email, "Katom photography  ", sBody);
	}
	public static class SMTPAuthenticator extends Authenticator
	{
		public PasswordAuthentication getPasswordAuthentication()
		{
			return new PasswordAuthentication(senderEmailID, senderPassword);
		}
	}

	/**
	 * @return the senderemailid
	 */
	public static String getSenderemailid() {
		return senderEmailID;
	}

	/**
	 * @return the senderpassword
	 */
	public static String getSenderpassword() {
		return senderPassword;
	}
	
	
}
